home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / ltmf_120.lzh / LTMF_ALT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-26  |  10.1 KB  |  357 lines

  1. /* ------------------------------------------------------------------------- */
  2. /* ----- Let 'em Fly!   V 1.2 ----------- (c) 1991-93 by Oliver Scheel ----- */
  3. /* ------------------------------------------------------------------------- */
  4. /* ----- Module: ltmf_alt.c   new form_alert() & new form_error() ---------- */
  5. /* ------------------------------------------------------------------------- */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <ctype.h>
  11. #include <macros.h>
  12. #include <smallaes.h>
  13. #include <vdi.h>
  14. #include <magx_old.h>
  15. #include <portab.h>
  16.  
  17. #include "ltmf_str.h"
  18. #include "letemfly.h"
  19. #include "ltmf_def.h"
  20.  
  21. /* ------------------------------------------------------------------------- */
  22.  
  23. int ltmf_init(void);
  24.  
  25. int nfm_do(OBJECT *tree, int startobj);
  26. int nfm_dial(int flag, int xs, int ys, int ws, int hs, int x, int y, int w, int h);
  27. int nfm_center(OBJECT *tree, int *x, int *y, int *w, int *h);
  28.  
  29. /* ------------------------------------------------------------------------- */
  30.  
  31. extern    int    gl_wchar,
  32.         gl_hchar,
  33.         gl_wbox,
  34.         gl_hbox;
  35.  
  36. extern    int    dialno;
  37.  
  38. extern    int    isalert,
  39.         infoflag;
  40.  
  41. EXTERN    OBJECT    *alert_dial;
  42.  
  43. extern    int    initflag;
  44.  
  45. extern    int    mousecnt;
  46. extern    int    was_used;
  47.  
  48. extern    MAGX_COOKIE    *magx;
  49.  
  50. extern    int    global[];
  51.  
  52. /* ------------------------------------------------------------------------- */
  53.  
  54. BITBLK    *al_icon[MAXICON];
  55. char    *al_text[5];
  56. char    *al_but[3];
  57.  
  58. char    al_string[MAXALCH];        /* alert-string buffer */
  59.  
  60. #ifdef ENGLISH
  61. char    *errstring[18]={"[1][",
  62.             "[1][|Invalid funktion number.|",
  63.             "[1][|File not found.|",
  64.             "[1][|Path not found.|",
  65.             "[1][|Too many open files.|",
  66.             "[1][Access denied.|(name conflict or write|protect)|",
  67.             "[1][|Invalid file handle.|",
  68.             "[1][|Out of memory.|",
  69.             "[1][|Invalid memory block adress.|",
  70.             "[1][|Invalid drive specification.|",
  71.             "[1][|Files are on differrent drives.|",
  72.             "[1][|No more files.|",
  73.             "[1][|Record is locked.|",
  74.             "[1][|No such lock.|",
  75.             "[1][|Range error.|",
  76.             "[1][Internal GEMDOS error.|(Congratulations!)|",
  77.             "[1][|Invalid executable file format.|",
  78.             "[1][|Memory block growth failure.|" };
  79. #else
  80. char    *errstring[18]={"[1][",
  81.             "[1][|Unbekannte Funktionsnummer.|",
  82.             "[1][|Datei nicht gefunden.|",
  83.             "[1][|Pfad nicht gefunden.|",
  84.             "[1][|Zu viele Dateien geöffnet.|",
  85.             "[1][Zugriff nicht erlaubt.|(Namenskonflikt oder Schreib-|schutz)|",
  86.             "[1][|Falsches Datei-Handle.|",
  87.             "[1][Nicht genügend Speicher|vorhanden.|",
  88.             "[1][Adresse des Speicherblocks|war nicht korrekt.|",
  89.             "[1][|Ungültige Laufwerksbezeichnung.|",
  90.             "[1][Dateien sind auf verschiedenen|Laufwerken.|",
  91.             "[1][Es können keine Dateien mehr|gefunden werden.|",
  92.             "[1][|Datei ist verschlossen (locked).|",
  93.             "[1][|`Lock' existiert nicht.|",
  94.             "[1][Dateizeiger in ungültigem|Bereich.|",
  95.             "[1][|Interner GEMDOS-Fehler (Bingo!).|",
  96.             "[1][|Datei ist kein Programm.|",
  97.             "[1][|Speicherblock kann nicht|vergrößert werden.|" };
  98. #endif
  99.  
  100. int    err_tab[37] = {    -1,  1,  2,  3,  4,  5,  6,  0,  7,  8,  0,  0,  0,  0,  0,  9,  0,
  101.             10, 11,  0,  0,  0,  0,  0,  0,  0,  0, 12, 13,  0,  0,  0,  0,
  102.             14, 15, 16, 17 };
  103.  
  104. #ifdef ETV_CRITIC
  105. #ifdef ENGLISH
  106. char    *ceh_str1[6]= {    "[4][|Device not ready!|Is it connected and activated?]",
  107.             "[4][Drive %: not ready!|Please check drive and insert|disk.]",
  108.             "[4][|Data on Drive %: fault?|Please check disk and wiring.]",
  109.             "[5][Disk in Drive %: is write|protected! Please remove|protection.]",
  110.             "[4][|Application can't read disk|in Drive %:.]",
  111.             "[6][|Please insert Disk %: in|Drive A:.][  OK  ]" };
  112. char    *ceh_but = {    "[Cancel|Retry|Ignore]" };
  113. #else
  114. char    *ceh_str1[6]= {    "[4][Ausgabegerät antwortet nicht!|Ist es angeschlossen und|eingeschaltet?]",
  115.             "[4][Laufwerk %: antwortet nicht!|Bitte überprüfen und eine|Disk einlegen.]",
  116.             "[4][Daten auf Disk %: defekt?|Prüfen Sie die Disk und die|Verbindungskabel.]",
  117.             "[5][Disk in Laufwerk %: ist schreib-|geschützt. Vor dem nächsten|Versuch den Schutz entfernen.]",
  118.             "[4][Die Anwendung kann die Disk|in Laufwerk %: nicht lesen.]",
  119.             "[6][|Bitte Disk %: in Laufwerk A:|einlegen.][  OK  ]" };
  120. char    *ceh_but = {    "[Abbruch|Nochmal|Ignorieren]" };
  121. #endif
  122.  
  123. char    ceh_tab[18] = {    0, 0, 1, 1, 2, 1, 1, 2, 2, 0, 2, 2, 2, 3, 4, 0, 2, 5 };
  124. #endif
  125.  
  126. /* ------------------------------------------------------------------------- */
  127. /* ----- new form_alert ---------------------------------------------------- */
  128. /* ------------------------------------------------------------------------- */
  129.  
  130. int _gettxt(char *dest[], char **source, int maxparts)
  131. {
  132.     int    i,
  133.         cont;
  134.     char    *strbeg;
  135.  
  136.     i = 0;
  137.     cont = TRUE;
  138.     while(**source && (i < maxparts) && cont)
  139.     {
  140.         strbeg = *source;
  141.         do
  142.         {
  143.             switch(**source)
  144.             {
  145.                 case ']'  :    cont = FALSE;
  146.                 case '|'  : **source = '\0';
  147.                         break;
  148.             }
  149.         }
  150.         while(*(*source)++);
  151.         dest[i++] = strbeg;
  152.     }
  153.     return(i);
  154. }
  155.  
  156. int _getmaxlen(char *str[], int cnt)
  157. {
  158.     int    i,
  159.         maxlen;
  160.  
  161.     maxlen = 0;
  162.     for(i = 0; i < cnt; i++)
  163.     {
  164.         if(strlen(str[i]) > maxlen)
  165.             maxlen = (int)strlen(str[i]);
  166.     }
  167.     return(maxlen);
  168. }
  169.         
  170. /* ------------------------------------------------------------------------- */
  171.  
  172. int nfm_alert(int but, char *string)
  173. {
  174.     int    i,
  175.         bh,
  176.         icon,
  177.         txtmax, butmax,
  178.         txtlen, butlen,
  179.         box_width, box_height,
  180.         exit_obj;
  181.     int    ms_on, wu_sav;
  182.     int    x, y, w, h;
  183.     char    *strbeg;
  184.     OBJECT    *ad;
  185.  
  186.     if(letemfly.conf & C_ALERT)
  187.     {
  188.         if(!initflag)
  189.             ltmf_init();
  190.         graf_handle(&gl_wchar, &gl_hchar, &gl_wbox, &gl_hbox);
  191.  
  192.         icon = string[1] - '0';
  193.         if(icon <= 3)
  194.         {
  195.             strncpy(al_string, string, MAXALCH);
  196.             al_string[MAXALCH-1] = '\0';
  197.         }
  198.         alert_dial[ALICON].ob_spec.bitblk = al_icon[icon];
  199. /*        alert_dial[ALICON].ob_spec.bitblk->bi_color = letemfly.aicol;
  200.         alert_dial[ALICON].ob_spec.bitblk->bi_pdata = al_icon[icon];
  201. */
  202. /*        alert_dial[ALICON].ob_y = gl_hchar/2 * 3;
  203. */
  204.         strbeg = al_string + 4l;
  205.         txtmax = _gettxt(&al_text, &strbeg, 5);
  206.         while(*strbeg++ != '[');
  207.         butmax = _gettxt(&al_but, &strbeg, 3);
  208.         txtlen = _getmaxlen(&al_text, txtmax);
  209.         butlen = _getmaxlen(&al_but, butmax) + 3;
  210.  
  211.         for(i = 0; i < txtmax; i++)
  212.         {
  213.             ad = &alert_dial[ALTEXT1+i];
  214.             ad->ob_next = ALTEXT1+i+1;
  215.             ad->ob_x = icon ? 64 : 16;
  216.             ad->ob_y = gl_hchar/2 + i * gl_hchar;
  217.             ad->ob_width = (int)strlen(al_text[i]) * gl_wchar;
  218.             ad->ob_spec.free_string = al_text[i];
  219.             ad->ob_flags &= ~HIDETREE;
  220.         }
  221.         alert_dial[ALTEXT1+i-1].ob_next = ALBUT1;
  222.         for(i = txtmax; i < 5; i++)
  223.             alert_dial[ALTEXT1+i].ob_flags |= HIDETREE;
  224.         box_width = max((icon ? 8 : 2) + txtlen + 2, butlen * butmax);
  225.         box_height = max(txtmax, icon ? (alert_dial[ALICON].ob_height / gl_hchar) : 0) + 3;
  226.         bh = (letemfly.conf & C_KEYS) ? 2 : 0;
  227.         for(i = 0; i < butmax; i++)
  228.         {
  229.             ad = &alert_dial[ALBUT1+i];
  230.             ad->ob_next = ALBUT1+i+1;
  231.             ad->ob_flags &= ~(LASTOB|HIDETREE|DEFAULT);
  232. /*            ad->ob_x = ((box_width - butlen * butmax) + butlen * i) * gl_wchar;
  233. */            ad->ob_x = ((box_width - butlen * butmax) / 2+ butlen * i + 1) * gl_wchar;
  234.             ad->ob_y = (box_height - 2) * gl_hchar + gl_hchar/2;
  235.             ad->ob_width = (butlen-2) * gl_wchar;
  236.             ad->ob_height = gl_hchar + bh;
  237.             ad->ob_spec.free_string = al_but[i];
  238.         }
  239.         i--;
  240.         alert_dial[ROOT].ob_tail = ALBUT1+i;
  241.         alert_dial[ALBUT1+i].ob_next = ROOT;
  242.         alert_dial[ALBUT1+i].ob_flags |= LASTOB;
  243.         for(i = butmax; i < 3; i++)
  244.             alert_dial[ALBUT1+i].ob_flags |= HIDETREE;
  245.         if(but)
  246.             alert_dial[ALBUT1+but-1].ob_flags |= DEFAULT;
  247.         alert_dial->ob_width = box_width * gl_wchar;
  248.         alert_dial->ob_height = box_height * gl_hchar + 2;
  249.         if(icon > 3)
  250.             alert_dial->ob_flags |= NOFLY;
  251.         else
  252.             alert_dial->ob_flags &= ~NOFLY;
  253.         alert_dial->ob_spec.obspec.framesize = letemfly.aframe;
  254.         alert_dial->ob_flags &= ~CENTER;
  255.         isalert = TRUE;
  256.         nfm_center(alert_dial, &x, &y, &w, &h);
  257.         wind_update(BEG_UPDATE);
  258.  
  259.         if((magx && (!magx->aesvars->moff_cnt) && (magx->aesvars->version == 0x0100)) ||
  260.             (!magx && (AESVersion() < 0x0400) && !mousecnt))
  261.         {
  262.             graf_mouse(M_ON, 0l);
  263.             ms_on = TRUE;
  264.         }
  265.         else
  266.             ms_on = FALSE;
  267.  
  268.         wu_sav = was_used;
  269.         nfm_dial(FMD_START, 0, 0, 0, 0, x, y, w, h);
  270.         objc_draw(alert_dial, ROOT, MAX_DEPTH, x, y, w, h);
  271.  
  272.         exit_obj = nfm_do(alert_dial, 0) & 0x7fff;
  273.  
  274.         nfm_dial(FMD_FINISH, 0, 0, 0, 0, x, y, w, h);
  275.         was_used = wu_sav;
  276.         if(ms_on)
  277.             graf_mouse(M_OFF, 0l);
  278.  
  279.         wind_update(END_UPDATE);
  280.         isalert = FALSE;
  281.         alert_dial[exit_obj].ob_state &= ~SELECTED;
  282.         return(exit_obj-ALBUT1+1);
  283.     }
  284.     else
  285.         return(form_alert(but, string));
  286. }
  287.  
  288. /* ------------------------------------------------------------------------- */
  289. /* ----- new form_error ---------------------------------------------------- */
  290. /* ------------------------------------------------------------------------- */
  291.  
  292. int nfm_error(int err)
  293. {
  294.     int    al;
  295.     char    err_str[128];
  296.  
  297.     if(letemfly.conf & C_ALERT)
  298.     {
  299.         if((err > 0) && (err < 64))
  300.         {
  301.             al = (err < 37) ? err_tab[err] : 0;
  302.             strcpy(err_str, errstring[al]);
  303. #ifdef ENGLISH
  304.             strcat(err_str, " |TOS Error #");
  305. #else
  306.             strcat(err_str, " |TOS Fehler #");
  307. #endif
  308.                 strcat(err_str, itoa(~(err + 30), "123456", 10));
  309.             strcat(err_str, "][  OK  ]");
  310.             nfm_alert(1, err_str);
  311.         }
  312.         return(0);
  313.     }
  314.     else
  315.         return(form_error(err));
  316. }
  317.  
  318. /* ------------------------------------------------------------------------- */
  319. /* ----- new etv_critic ---------------------------------------------------- */
  320. /* ------------------------------------------------------------------------- */
  321. #ifdef ETV_CRITIC
  322.  
  323. long netv_critic(int err, int drive)
  324. {
  325.     long    result;
  326.     int    choice;
  327.     char    *txtp;
  328.  
  329.     if(err < 0)
  330.     {
  331.         err = -err;
  332.         strcpy(al_string, ceh_str1[ceh_tab[err]]);
  333.         if(err != 17)
  334.             strcat(al_string, ceh_but);
  335.         txtp = al_string;
  336.         while(*txtp && (*txtp != '%'))
  337.             txtp++;
  338.         if(*txtp == '%')
  339.             *txtp = drive + 'A';
  340.         choice = nfm_alert((err == 17) ? 1 : 2, al_string);
  341.         switch(choice)
  342.         {
  343.             case 1    :    result = (long)-err;
  344.                     break;
  345.             case 2    : result = 0x10000L;
  346.                     break;
  347.             case 3    : result = 0x0L;
  348.         }
  349.         if(err == 17)
  350.             result = 0x10000L;
  351.         return(result);
  352.     }
  353.     return((long)err);
  354. }
  355.  
  356. #endif
  357.